<template>
    <div class="media-image-list">
        <ul>
            <li v-for="item in list" :key="item.id">
                <figure @click="setSelect($event, item)">
                    <img crossOrigin="anonymous" v-lazy="getLitimg(item.img_url, 'medium')"
                        :style="$fiexImage(item.width, item.height, 1)" />
                </figure>
                <strong v-text="item.img_name"></strong>
                <span v-text="item.width + '×' + item.height + 'px'"></span>
                <!-- <span v-text="item.width + '×' + item.height + 'px.' + item.img_type"></span> -->
            </li>
        </ul>
    </div>
</template>
<script>
import DesignResource from "@/utils/DesignResource.js";
export default {
    props: {
        list: { type: Array, default: () => [] },
    },
    data () {
        return {
        };
    },
    methods: {

        getLitimg (url, type) {
            let cache = DesignResource.getImageByCache(url, {
                type: "simple",
                form: "materials",
            });
            if (cache) {
                return cache.src;
            } else {
                return this.$getLitimgUrl(url, type)
            }
        },

        // 选中
        setSelect (event, item) {
            event.stopPropagation();
            event.preventDefault();
            this.$emit('select', item)
        },

    },
};
</script>

<style lang="scss" scoped>
.media-image-list {
    background: #ffffff;
    border-radius: 8px;
    border: 1px solid #e6e6e6;

    ul {
        display: flex;
        flex-wrap: wrap;
        margin: 12px 12px;
    }

    li {
        width: calc(16.66% - 16px);
        display: flex;
        flex-direction: column;
        margin: 8px;
        box-sizing: border-box;
        position: relative;
        align-items: center;

        figure {
            width: 100%;
            position: relative;
            background: #f8f8f8;
            border-radius: 4px;
            border: 1px solid #f0f0f0;
            cursor: pointer;
            transition: 0.2s box-shadow;

            &::before {
                content: "";
                display: block;
                padding-bottom: 100%;
            }

            img {
                position: absolute;
                left: 0;
                top: 0;
                width: 100%;
                height: 100%;
            }

            &:hover {
                box-shadow: 0px 4px 8px 0px rgba(0, 0, 0, 0.12);
            }
        }

        strong {
            width: 100%;
            max-height: 36px;
            position: relative;
            font-size: 14px;
            font-family: Roboto-Regular, Roboto;
            font-weight: 400;
            color: #000000;
            line-height: 18px;
            margin-top: 12px;
            white-space: normal;
            word-break: break-all;
            line-clamp: 2;
            overflow: hidden;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            text-overflow: ellipsis;
            -webkit-line-clamp: 2;
        }

        span {
            margin-top: 6px;
            font-size: 14px;
            font-family: Roboto-Regular, Roboto;
            font-weight: 400;
            color: #757575;
            line-height: 16px;
            width: 100%;
        }
    }
}
</style>
